package com.cxj.magic;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class TouchExampleView extends View
{
  public int imgid = 2130837505;
  private VersionedGestureDetector mDetector;
  private Drawable mIcon;
  private float mPosX;
  private float mPosY;
  private float mScaleFactor = 1.0F;
  
  public TouchExampleView(Context paramContext, int paramInt)
  {
    this(paramContext, null, 0);
    this.imgid = paramInt;
    this.mIcon = paramContext.getResources().getDrawable(paramInt);
    this.mIcon.setBounds(0, 0, this.mIcon.getIntrinsicWidth(), this.mIcon.getIntrinsicHeight());
    this.mDetector = VersionedGestureDetector.newInstance(paramContext, new GestureCallback());
  }

  public TouchExampleView(Context paramContext, AttributeSet paramAttributeSet)
  {
    this(paramContext, paramAttributeSet, 0);
  }

  public TouchExampleView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
  }

  public void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    paramCanvas.save();
    paramCanvas.translate(this.mPosX, this.mPosY);
    paramCanvas.scale(this.mScaleFactor, this.mScaleFactor);
    this.mIcon.draw(paramCanvas);
    paramCanvas.restore();
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    this.mDetector.onTouchEvent(paramMotionEvent);
    return true;
  }

  private class GestureCallback
    implements VersionedGestureDetector.OnGestureListener
  {
    private GestureCallback()
    {
    }

    public void onDrag(float paramFloat1, float paramFloat2)
    {
      TouchExampleView localTouchExampleView1 = TouchExampleView.this;
      localTouchExampleView1.mPosX = (paramFloat1 + localTouchExampleView1.mPosX);
      TouchExampleView localTouchExampleView2 = TouchExampleView.this;
      localTouchExampleView2.mPosY = (paramFloat2 + localTouchExampleView2.mPosY);
      TouchExampleView.this.invalidate();
    }

    public void onScale(float paramFloat)
    {
      TouchExampleView localTouchExampleView = TouchExampleView.this;
      localTouchExampleView.mScaleFactor = (paramFloat * localTouchExampleView.mScaleFactor);
      TouchExampleView.this.mScaleFactor = Math.max(0.1F, Math.min(TouchExampleView.this.mScaleFactor, 5.0F));
      TouchExampleView.this.invalidate();
    }
  }
}